package com.company.controller;

import com.company.entity.Company;
import com.company.fegin.ShopClient;
import com.company.fegin.entity.Shop;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author yinxing
 * @date 2022-08-05
 */
@RestController
public class VisitController {

    @Resource
    private ShopClient shopClient;

    /**
     * 访问自己
     *
     * @param company
     * @return
     */
    @RequestMapping("/visit")
    public String visit(@RequestBody Company company) {
        return company.getResource() + " visit the company";
    }

    /**
     * 访问商店
     *
     * @param shop
     * @return
     */
    @RequestMapping("/testCompany")
    public String testCompany(@RequestBody Shop shop) {
        return shopClient.visit(shop);
    }

    @RequestMapping("/ribbonShopAndSuper")
    @HystrixCommand(fallbackMethod = "fallBack")
    public String ribbonShopAndSuper(){
        return shopClient.hello();
    }

    public String fallBack(){
        return "hystrix : shop server down!";
    }

    @RequestMapping("/hello")
    public String hello(){
        return "this is company say hello !";
    }
}
